import CryptoJS from 'crypto-js';

export class AccessToken {
    static async createToken(accessKeyId: string, accessKeySecret: string) {
        const timestamp = Math.floor(Date.now() / 1000);
        const nonce = Math.floor(Math.random() * 100000);
        const expireTime = timestamp + 3600; // 1小时过期

        const stringToSign = `${accessKeyId}&${timestamp}&${nonce}&${expireTime}`;
        const signature = CryptoJS.HmacSHA1(stringToSign, accessKeySecret).toString(CryptoJS.enc.Base64);
        const token = `${stringToSign}&${signature}`;

        return {
            token,
            expireTime
        };
    }
} 